package jp.reflexworks.invoice.model;

import java.text.DecimalFormat;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.google.appengine.api.datastore.Key;

@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class Order {

	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	private Key key;

	@Persistent
	private Invoice invoice;
	@Persistent
	private long id;
	@Persistent
	public String invoiceNo;		// 受注レコードとの関連をひもづける
	@Persistent
	public String seqno;
	@Persistent
	public String productcd;
	@Persistent
	public String description;
	@Persistent
	public String quantity;
	@Persistent
	public String unitPrice;
	@Persistent
	public String lineTotal;

	// 1だとtrue(削除済)
	@Persistent
	public int deleted;

	// View -> JDO 
	public void convertTo() {
		// カンマを外す
		this.unitPrice = this.unitPrice.replaceAll(",",""); 	
		this.lineTotal = this.lineTotal.replaceAll(",",""); 	
	}

	// JDO -> View 
	public void convertFrom() {
		// カンマをつける
		DecimalFormat formatter = new DecimalFormat("#,###"); 		 
		this.unitPrice = formatter.format(Integer.parseInt(this.unitPrice)); 	
		this.lineTotal = formatter.format(Integer.parseInt(this.lineTotal)); 	
	}

	public String getInvoiceNo() {
		return invoiceNo;
	}
	public void setInvoiceNo(String invoiceNo) {
		this.invoiceNo = invoiceNo;
	}
	public String getSeqno() {
		return seqno;
	}
	public void setSeqno(String seqno) {
		this.seqno = seqno;
	}
	public String getDescription() {
		return description;
	}
	public void setDescription(String description) {
		this.description = description;
	}
	public String getQuantity() {
		return quantity;
	}
	public void setQuantity(String quantity) {
		this.quantity = quantity;
	}
	public String getUnitPrice() {
		return unitPrice;
	}
	public void setUnitPrice(String unitPrice) {
		this.unitPrice = unitPrice;
	}
	public String getLineTotal() {
		return lineTotal;
	}
	public void setLineTotal(String lineTotal) {
		this.lineTotal = lineTotal;
	}

	public Key getKey() {
		return key;
	}

	public void setKey(Key key) {
		this.key = key;
	}

	public Invoice getInvoice() {
		return invoice;
	}

	public void setInvoice(Invoice invoice) {
		this.invoice = invoice;
	}

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public int getDeleted() {
		return deleted;
	}

	public void setDeleted(int deleted) {
		this.deleted = deleted;
	}

	public String getProductcd() {
		return productcd;
	}

	public void setProductcd(String productcd) {
		this.productcd = productcd;
	}
	
	
	
}
